const logUtil = require('../utils/log_util');

const logsWriter = () => {
    return async (ctx, next) => {
        const start = new Date();
        // 响应间隔时间
        var ms;
        await next();
        ms = new Date() - start;
        // 记录响应日志
        logUtil.logResponse(ctx, ms);
        console.log(`${
            ctx.method
        } ${
            ctx.url
        } - ${ms}ms`)
    }
}

module.exports = logsWriter
